package website.lhc.commo.exceptions;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import website.lhc.commo.base.Resp;

/**
 * @ProjectName: springboot
 * @Package: website.lhc.commo.exceptions
 * @ClassName: GlobalExceptionHandler
 * @Author: lhc
 * @Description: TODO
 * @Date: 2020/7/5 下午 10:30
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 捕获约束不匹配异常和断言异常
     *
     * @param e ConstraintNotMatchException
     * @return Resp
     */
    @ExceptionHandler(value = {ConstraintNotMatchException.class, AssertException.class})
    public Resp handlerConstraintNotMatchException(ConstraintNotMatchException e) {
        return Resp.error(e.getMessage());
    }
}
